package top.sunpxit.generator.config;

import lombok.AccessLevel;
import lombok.Data;
import lombok.Setter;
import lombok.experimental.Accessors;
import top.sunpxit.generator.primary.PrimaryKeyStrategyEnum;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * 系统配置
 *
 * @program: set-sail-generator
 * @description:
 * @author: sunpx
 * @create: 2021-03-26 13:08
 **/
@Data
@Accessors(chain = true)
public class SystemConfig {

    /**
     * 要生成的表名称为空代表生成所有
     */
    private List<String> tableList;

    /**
     * 是否下划线转驼峰
     */
    private boolean isToHump;

    /**
     * 主键生成策略(默认自动分配雪花算法)
     */
    private PrimaryKeyStrategyEnum primaryKeyStrategy = PrimaryKeyStrategyEnum.ASSIGN_ID;

    /**
     * 数据库驱动
     */
    @Setter(AccessLevel.NONE)
    private String driver;

    /**
     * 数据库连接
     */
    @Setter(AccessLevel.NONE)
    private String url;

    /**
     * 数据库用户名
     */
    @Setter(AccessLevel.NONE)
    private String userName;

    /**
     * 数据库密码
     */
    @Setter(AccessLevel.NONE)
    private String password;


    //controller包名
    private String controller = "controller";

    //实体类包名
    private String entity = "entity";

    //业务包名
    private String service = "service";

    //mapper包名
    private String mapper = "mapper";

    //包配置
    private String packagePath;

    //模块名称
    private String moduleName;

    //统一结果集包路径 默认${packagePath}.commons.result
    private String UnifiedResultPath=packagePath+".commons.result";

    //统一结果集名称默认名称R
    private String UnifiedResultName="R";



    /**
     * 加载数据库
     * @author: sunpx
     * @param driver 驱动
     * @param url 连接
     * @param username 用户名
     * @param password 密码
     * @ date : 2021-03-26 13:40:42
     */
    public SystemConfig(String driver, String url, String username, String password) throws SQLException, ClassNotFoundException {
        this.driver=driver;
        this.url=url;
        this.userName=username;
        this.password=password;
        DataSourceConfig.initDataSource(driver,url,username,password);
    }
}
